<template>
	<view>
		<view class="head">
			<view class="left">
				<view class="headImg">
					<image :src="evaluateList.head_url" mode=""></image>
				</view>
				<view class="name">{{evaluateList.m_name}}</view>
			</view>
			<view class="right">
				<view class="item">服务天数: {{evaluateList.days}}天</view>
				<view class="item">联系人: {{evaluateList.name}}</view>
				<view class="item">联系电话: {{evaluateList.mobile}}</view>
				<view class="item">详细地址: {{evaluateList.address}}</view>
			</view>
		</view>
		<view class="grade">
			<view class="title">月嫂评分:</view>
			<view class="content">
				<view class="item">
					<text class="name">宝宝护理</text>
					<uni-icon type="like" size="15" :color="item" v-for="(item, index) in likeList0" :key="index" @click="iconBtn0(index)"></uni-icon>
				</view>
				<view class="item">
					<text class="name">宝宝早教</text>
					<uni-icon type="like" size="15" :color="item" v-for="(item, index) in likeList1" :key="index" @click="iconBtn1(index)"></uni-icon>
				</view>
				<view class="item">
					<text class="name">膳食搭配</text>
					<uni-icon type="like" size="15" :color="item" v-for="(item, index) in likeList2" :key="index" @click="iconBtn2(index)"></uni-icon>
				</view>
				<view class="item">
					<text class="name">科学喂养</text>
					<uni-icon type="like" size="15" :color="item" v-for="(item, index) in likeList3" :key="index" @click="iconBtn3(index)"></uni-icon>
				</view>
				<view class="item">
					<text class="name">产妇护理</text>
					<uni-icon type="like" size="15" :color="item" v-for="(item, index) in likeList4" :key="index" @click="iconBtn4(index)"></uni-icon>
				</view>
				<view class="item">
					<text class="name">沟通技巧</text>
					<uni-icon type="like" size="15" :color="item" v-for="(item, index) in likeList5" :key="index" @click="iconBtn5(index)"></uni-icon>
				</view>
			</view>
		</view>
		<form @submit="submitBtn">
			<view class="evaluate">
				<view class="title">填写评价:</view>
				<textarea value="" placeholder="期待您的真诚反馈.." placeholder-style="color: #878787;font-size:12px;" @input="bindTextArea" name="content" />
				<text>{{cursor}}/140</text>
			</view>
			<button form-type="submit">提交</button>
		</form>
	</view>
</template>

<script>
	import uniIcon from "@/components/uni-icon/uni-icon.vue";
	import { dns } from "@/pages/dns.js"
	export default {
		data(){
			return {
				evaluateList: [],
				likeList0: ['#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8'],
				likeList1: ['#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8'],
				likeList2: ['#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8'],
				likeList3: ['#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8'],
				likeList4: ['#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8'],
				likeList5: ['#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8'],
				id: '',
				b_nursing: 0,
				early_education: 0,
				collocation: 0,
				feed: 0,
				m_nursing: 0,
				communicate: 0,
				cursor: 0,//备注的字数
			}
		},
		components: {
			uniIcon
		},
		onLoad(e) {
			this.id = e.id;
			this.getEvaluate(e.id);
		},
		methods:{
			bindTextArea(e){//输入框输入事件
				this.cursor = e.detail.cursor;
			},
			getEvaluate(id){//获取评论基本信息
				uni.request({
					method: 'GET',
					data: {
						id
					},
					header:{
						token: uni.getStorageSync("token")
					},
					url: dns + 'order/evaluate_detail',
					success: (res)=>{
						if(res.data.status == 1){
							this.evaluateList = res.data.data;
						}
					}
				})
			},
			submitBtn(e){
				var content = e.detail.value.content;
				if(this.b_nursing == 0||this.early_education == 0||this.collocation == 0||this.feed == 0||this.m_nursing == 0||this.communicate == 0){
					uni.showToast({
						icon: 'none',
						title: '请完善您的评分'
					})
					return;
				};
				uni.request({
					method: 'POST',
					data: {
						id: this.id,
						content: content,
						b_nursing: this.b_nursing,
						early_education: this.early_education,
						collocation: this.collocation,
						feed: this.feed,
						m_nursing: this.m_nursing,
						communicate: this.communicate
					},
					header:{
						token: uni.getStorageSync("token")
					},
					url: dns + 'order/evaluate',
					success: (res)=>{
						if(res.data.status == 1){
							uni.showToast({
								title: res.data.msg
							})
							var pages=getCurrentPages();
							var prevPage=pages[pages.length-2];//上一页面
							prevPage.ifdelete = 1;
							setTimeout(()=>{
								uni.navigateBack({
									delta:1
								})
							},1000)
						}
						if(res.data.status == 0){
							uni.showToast({
								icon: 'none',
								title: res.data.msg
							})
						}
					}
				})
			},
			iconBtn0(index){
				var likeList = ['#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8'];
				likeList.forEach((val,ind)=>{
					if(ind<=index){
						likeList[ind] = '#e04f47'
					}
				})
				this.likeList0 = likeList;
				this.b_nursing = index+1;
			},
			iconBtn1(index){
				var likeList = ['#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8'];
				likeList.forEach((val,ind)=>{
					if(ind<=index){
						likeList[ind] = '#e04f47'
					}
				})
				this.likeList1 = likeList;
				this.early_education = index+1;
			},
			iconBtn2(index){
				var likeList = ['#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8'];
				likeList.forEach((val,ind)=>{
					if(ind<=index){
						likeList[ind] = '#e04f47'
					}
				})
				this.likeList2 = likeList;
				this.collocation = index+1;
			},
			iconBtn3(index){
				var likeList = ['#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8'];
				likeList.forEach((val,ind)=>{
					if(ind<=index){
						likeList[ind] = '#e04f47'
					}
				})
				this.likeList3 = likeList;
				this.feed = index+1;
			},
			iconBtn4(index){
				var likeList = ['#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8'];
				likeList.forEach((val,ind)=>{
					if(ind<=index){
						likeList[ind] = '#e04f47'
					}
				})
				this.likeList4 = likeList;
				this.m_nursing = index+1;
			},
			iconBtn5(index){
				var likeList = ['#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8','#e8e8e8'];
				likeList.forEach((val,ind)=>{
					if(ind<=index){
						likeList[ind] = '#e04f47'
					}
				})
				this.likeList5 = likeList;
				this.communicate = index+1;
			}
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
		background-color: #f6f6f6;
	}
	.head{
		margin: 0 20upx;
		display: flex;
		background-color: #fff;
		margin-top: 20upx;
		padding: 20upx;
		font-size: 24upx;
		.left{
			width: 140upx;
			margin-right: 40upx;
			.headImg{
				width: 100%;
				height: 140upx;
				border-radius: 50%;
				overflow: hidden;
				image{
					width: 100%;
					height: 100%;
				}
			}
			.name{
				font-size: 30upx;
				text-align: center;
				margin-top: 10upx;
			}
		}
		.right{
			display: flex;
			flex-flow: column;
			justify-content: space-between;
			padding: 20upx 0;
			flex: 1;
			.item{
				width: 480upx;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
			}
		}
	}
	.grade{
		margin: 0 20upx 0 20upx;
		border-top: 1px solid #eee;
		background-color: #fff;
		font-size: 28upx;
		padding: 20upx;
		color: #676767;
		.title{
			color: #000;
			margin-bottom: 20upx;
		}
		.content{
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			.item{
				width: 50%;
				margin-bottom: 10upx;
				.name{
					margin-right: 10upx;
				}
				uni-icon{
					vertical-align: middle;
					margin-left: 10upx;
				}
				.grade{
					margin-left: 10upx;
					vertical-align: top;
					color: #e04f47;
				}
			}
			.item:nth-of-type(2n){
				text-align: right;
			}
		}
	}
	.evaluate{
		margin: 20upx 20upx 0 20upx;
		background-color: #fff;
		color: #000;
		font-size: 26upx;
		padding: 20upx;
		position: relative;
		textarea{
			width: 100%;
			height: 300upx;
			padding:20upx;
			color: #878787;
			font-size:12px;
		}
		text{
			position: absolute;
			bottom: 20upx;
			right: 30upx;
			font-size: 24upx;
			color: #878787;
		}
	}
	button{
		background-color: #e04f47;
		color: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		font-size: 34upx;
		border-radius: 0;
	}
</style>
